import smtplib
from email.mime.text import MIMEText

def send_email(subject, body, from_, to):
    msg = MIMEText(body, 'html')
    msg['Subject'] = subject
    msg['From'] = from_
    msg['To'] = to
    s = smtplib.SMTP()
    s.sendmail(me, [you], msg.as_string())


GMAIL_LOGIN = ''
GMAIL_PASSWORD = ''
 
 
def send_email_by_gmail(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN, html=True):
    msg = MIMEText(message, 'html' if html else 'text')
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr
 
    server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
    try:
        server.ehlo()
        server.starttls()
        server.ehlo()
        server.login(GMAIL_LOGIN,GMAIL_PASSWORD)
        server.sendmail(from_addr, to_addr, msg.as_string())
    finally:
        try:
            server.close()
        except:
            pass

